 <template>
  <div class="index-box" ref="index">
    <el-row :gutter="10">
      <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
        <div class="moneyTotal" ref="moneyTotal">
            <div class="item">
              <div class="money"><span>{{topData.totalWithdrawalAmount}}</span>元</div>
              <div class="text">提现总金额</div>
            </div>
            <div class="item">
              <div class="money">¥<span>{{topData.haveWithdrawalAmount}}</span>元</div>
              <div class="text">已提现总金额</div>
            </div>
            <div class="item">
              <div class="money">￥<span >{{topData.availableAmountWithdrawn}}</span>元</div>
              <div class="text">可提现总金额</div>
            </div>
            <div class="item">
              <div class="money">￥<span>{{topData.totalCommissionAmount}}</span>元</div>
              <div class="text">手续费总金额</div>
            </div>
        </div>
        <div class="search" ref="search">
          <el-form :inline="true" :model="searchForm" size="small" ref="searchForm" @submit.native.prevent  class="demo-form-inline" id="searchBox">
            <el-form-item prop="telephone">
                <el-input v-model="searchForm.telephone" clearable placeholder="用户手机号"></el-input>
            </el-form-item>
            <el-form-item prop="userName">
                <el-input v-model="searchForm.userName" clearable placeholder="用户名"></el-input>
            </el-form-item>

            <el-form-item prop="time">
              <el-date-picker v-model="time" type="daterange" align="right" unlink-panels range-separator="至"
                start-placeholder="更新开始日期" end-placeholder="下单结束日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
                :picker-options="pickerOptions">
              </el-date-picker>
            </el-form-item>


            <el-form-item class="clearfix">
              <el-button type="primary" @click="handleSearch()" icon="el-icon-search">搜索</el-button>
              <el-button icon="el-icon-refresh" size="small" @click="resetSeach">重置</el-button>
            </el-form-item>
          </el-form>
        </div>
        <div class="actionBtn" ref="actionBtn">
         <div class="actionBtnLeft">
           <el-radio-group v-model="searchForm.levelId" size="small" @change="handleSearch">
             <el-radio-button label="">全部</el-radio-button>
             <el-radio-button :label="item.levelId" v-for="item in levelList">{{item.name}}</el-radio-button>
           </el-radio-group>
           <el-button
             style="margin-left:10px;"
             type="warning"
             icon="el-icon-download"
             size="small"
             :loading="btnLoading"
             @click="handleExport"
             v-has="'statistics:userWithdraw:export'"
           >导出</el-button>
         </div>
          <div class="actionBtnRight">
              <MyRefresh></MyRefresh>
              <MyTableColumnSet :tableColumn.sync="tableColumn" :hideTableColumn.sync="hideTableColumn" :tableColumnType.sync="tableColumnType"></MyTableColumnSet>
          </div>
        </div>
        <div class="table" ref="table">
          <el-table :data="dataList" style="width: 100%" row-key="id" v-loading="loading" border :height="tableHeight"  stripe>
            <el-table-column prop="userface" label="用户头像" v-if="!hideTableColumn.includes('userface')" width="100" align="center">
              <template #default="scope">
                 <el-image :src="scope.row.userface" fit="fill" v-image-preview="scope.row.userface" class="img"></el-image>
              </template>
            </el-table-column>
            <el-table-column prop="userName" label="用户名" v-if="!hideTableColumn.includes('userName')" align="center"></el-table-column>
            <el-table-column prop="telphone" label="手机号" v-if="!hideTableColumn.includes('telphone')" align="center"></el-table-column>
            <el-table-column prop="levelName" label="加盟会员等级" v-if="!hideTableColumn.includes('levelName')" align="center"></el-table-column>
            <el-table-column prop="withdrawalTotalAmount" label="提现总金额(元)" v-if="!hideTableColumn.includes('withdrawalTotalAmount')" align="center"></el-table-column>
            <el-table-column prop="haveWithdrawal" label="已提现(元)" v-if="!hideTableColumn.includes('haveWithdrawal')" align="center"></el-table-column>
            <el-table-column prop="canWithdraw" label="可提现(元)" v-if="!hideTableColumn.includes('canWithdraw')" align="center"></el-table-column>
            <el-table-column prop="withdrawCount" label="总提现次数" v-if="!hideTableColumn.includes('withdrawCount')" align="center"></el-table-column>
            <el-table-column prop="totalFeeAmount" label="手续费总金额" v-if="!hideTableColumn.includes('totalFeeAmount')" align="center"></el-table-column>
            <el-table-column prop="storeAmount" label="操作" v-if="!hideTableColumn.includes('storeAmount')" align="center" fixed="right">
              <template #default="scope">
                <div class="verticalBtn">
                  <el-button
                    size="medium"
                    type="text"
                    icon="el-icon-view"
                     v-has="'statistics:userWithdraw:record'"
                    @click="handleWithdrawRecord(scope.row)"
                  >提现记录</el-button>
                </div>
              </template>
            </el-table-column>

          </el-table>
        </div>
        <div class="page" ref="page">
          <MyPagination
            :total="total"
            :page.sync="searchForm.pageNum"
            :limit.sync="searchForm.pageSize"
            @pagination="dataInfo"
          />
        </div>
      </el-col>
    </el-row>

    <!-- 提现记录 -->
    <el-dialog title="提现记录" width="800px" v-dialogDrag :visible.sync="recordVisible" @close="recordVisible = false">
      <div style="text-align: center;margin-bottom: 10px;">手机号为 {{statusRow.telphone}} 用户的提现记录</div>
      <el-table :data="recordList" style="width: 100%"  v-loading="tableLoading" border  stripe>
        <el-table-column prop="code" label="提现编号" align="center"></el-table-column>
        <el-table-column prop="total" label="提现金额(元)" align="center"></el-table-column>
        <el-table-column prop="serviceFee" label="手续费" align="center"></el-table-column>
        <el-table-column prop="userName" label="提现状态" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status=='1'">待审核</el-tag>
            <el-tag v-else-if="scope.row.status=='2'" type="success">通过</el-tag>
            <el-tag v-else-if="scope.row.status=='3'" type="warning">驳回</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="userName" label="更新时间" align="center" width="160">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.modifyDate) }}</span>
          </template>
        </el-table-column>
      </el-table>

    </el-dialog>

  </div>
</template>

<script>
  import common from '@/api/api';
  import {
    withdrawalList,withdrawalMessage,getWithdrawalQuantity,withdrawalExport,getAllMemberLevel
  } from '@/api/getData'
  import option from '../../common/option.js';

  export default {
    data() {
      return {
        loading: false,
        btnLoading:false,
        time:[],
        searchForm: {
          telephone:'',
          userName:'',
          levelId:'',

          settlementStatus:'0',
          pageNum:1,
          pageSize:20,
        },
        total: 0,
        tableColumn:[{/*自定义表格列*/
            name:'用户头像',
            value:'userface'
        },{
            name:'用户名',
            value:'userName'
        },{
            name:'手机号',
            value:'telphone'
        },{
            name:'加盟会员等级',
            value:'levelName'
        },{
            name:'提现总金额(元)',
            value:'withdrawalTotalAmount'
        },{
            name:'已提现(元)',
            value:'haveWithdrawal'
        },{
            name:'可提现(元)',
            value:'canWithdraw'
        },{
            name:'总提现次数',
            value:'withdrawCount'
        },{
            name:'手续费总金额',
            value:'totalFeeAmount'
        }],
        hideTableColumn:[],/*自定义表格列需要隐藏的*/
        tableColumnType:'staffManagement',/*自定义表格列类型传参*/
        tableHeight:0,//table 高度
        dataList:[],
        topData:{},//头部数据
        levelList:[],

        statusRow:{},
        tableLoading:false,
        recordVisible:false,
        recordList:[]
      }
    },
    created() {

    },
    mounted() {
      this.getSelect();
      this.topDataInfo();
      this.dataInfo();
      this.$nextTick(() => {
          this.tableHeight = this.$refs.index.offsetHeight - this.$refs.moneyTotal.offsetHeight - this.$refs.search.offsetHeight  - this.$refs.actionBtn.offsetHeight - this.$refs.page.offsetHeight - 55;
      })
    },
    computed:{
      pickerOptions: () => {
        return option.pickerOptions;
      }
    },
    methods: {
      getSelect(){
        getAllMemberLevel().then(res=>{
          let list = res.data;
          list.map(item=>{
            item.nameMoney = item.levelId!='1'?item.name+"("+item.unionFee+"万元加盟金)":item.name
          })
          this.levelList = list;
        })
      },
      topDataInfo(){
        let data = this.addDateRange(this.searchForm, this.time, 'startTime', 'endTime');
        getWithdrawalQuantity(data).then((res)=>{
          this.topData = res.data;
        })
      },
      resetSeach(){
        this.time = [];
        this.resetForm('searchForm');
        this.dataInfo();
        this.topDataInfo();
      },
      /** 提现记录 **/
      handleWithdrawRecord(row){
        this.recordVisible = true;
        this.statusRow = row;
        this.tableLoading = true;
        withdrawalMessage({customerId:row.customerId}).then(res=>{
          if(res.code){
              this.recordList = res.data;
          }else{
            this.$message.error(res.msg)
          }
          this.tableLoading = false;
        })
      },
      /** 导出按钮操作 */
      handleExport() {
        let data = this.addDateRange(this.searchForm, this.time, 'startTime', 'endTime');
        this.$modal.confirm('是否确认导出搜索数据项？').then(() => {
          this.btnLoading = true;
          return withdrawalExport(data);
        }).then(response => {
          this.$download.name(response.msg);
          this.btnLoading = false;
        }).catch(() => {});
     },
     handleSearch(){
         this.page = 1;
         this.dataInfo();
         this.topDataInfo();
     },
     async dataInfo() {
       try {
         let data = this.addDateRange(this.searchForm, this.time, 'startTime', 'endTime');
         this.loading = true;
         const result = await withdrawalList(data);
         if (result.code == 200) {
           this.total = result.total;
           this.dataList = result.rows;
         } else {
           this.$message.error(result.msg);
         }
         this.loading = false;
       } catch (err) {
         this.loading = false;
         console.log(err)
       }
     },
    }
  }
</script>

<style scoped lang="scss">
  .red{
    color:red;
  }
  .el-table .el-dropdown-link{
      cursor: pointer;
      color: #61997A;
      margin-left: 5px;
  }
    .leftDialog{
      height:540px;
      overflow-y: auto;
    }
    .activeVerticalBox .activeItem{
      color:#61997A;
      cursor: pointer;
      margin: 0px;
      text-align: center;
      height:20px;
      line-height: 20px;
    }
    .activeVerticalBox .el-dropdown{
      display: flex;
      justify-content: center;
      color:#61997A;
      cursor: pointer;
    }
    .activeCheckedBox{
      border-top: 1px solid #ddd;
      padding:10px;
      height:52px;
      .el-tag{
        margin-right:10px;
      }
    }
    .rateBox /deep/ .el-rate__icon{
      margin-right: 0px;
    }
    .rateBox>p{
      margin: 0px;
    }
    .rateBox>p> /deep/ .el-rate{
      height:25px;
      line-height:25px;
      display:flex;
    }
    .rateBox>p> /deep/ .el-rate .el-rate__item{
      display:flex;
      align-items: center;
    }
    .rateBox .rateText{
      width:60px;
    }
    .rateBox .content{
      display: flex;
    }
    .rateBox .el-tooltip{
      width: 100px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      display: inline-block;
    }
</style>
